<template>
    <bSearch :instance="mSearch"></bSearch>
    <bList :instance="pList" @about="(data) => pList.info(data.id)"></bList>
    <Popup v-model:show="dForm._show" :title="dForm.title" :destroyOnClose="true">
        <bForm :instance="dForm" cover="50%">
            <Button @click="onUpdate">完成</Button>
        </bForm>
    </Popup>
</template>

<script setup lang="ts">
import { IList, IForm, IListSearch } from "@b/index/nursing_appointment";
import bList from "@m/components/public/b_list.vue";
import bSearch from "@m/components/public/b_search.vue";
import bForm from "@m/components/public/b_form.vue";
import { Popup, Button } from "vant";
import { useRouter } from "vue-router";
/* import-and-register */

const mSearch = new IListSearch();
const pList = new IList();
const dForm = new IForm();
const router = useRouter();
/* const-and-register */

mSearch.init();

mSearch.onSearch = () => {
    //解构（浅拷贝，防止存在查询条件时点击页码产生的混乱）
    pList.search_key = mSearch.getData();
    pList.refresh(1);
};

pList.info = async (id: number) => {
    if (!id) return;
    router.push(`/nursing_appointment/info/audit?id=${id}`)
};
pList.add = async () => {
    dForm._show = true;
    dForm.title = "添加订单";
};
const onUpdate = async () => {
    const res = await dForm.updateData();
    if (res) {
        dForm._show = false;
        pList.refresh();
    }
};
/* event-and-register */
</script>